package com.unicom.office.func;

import com.unicom.office.dataitem.NumberDataItem;
import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.type.TextRangeTypeItem;
import com.unicom.office.type.TypeItem;
import com.unicom.office.unit.OfficeUnit;
import com.unicom.office.unit.TextRangeUnit;

public class TextRangeFunc extends FuncBase {
    private FuncBase funcBase;
    private Object source;

    public TextRangeFunc(Object source, FuncBase funcBase) {
        this.funcBase = funcBase;
        this.source = source;
    }

    public Object run(OfficeRuntime officeRuntime) {
        TextRangeUnit textRangeUnit = new TextRangeUnit();
        textRangeUnit.setSource(source);
        Object run = funcBase.run(officeRuntime);
        textRangeUnit.setText(run.toString(), run instanceof NumberDataItem);
        return textRangeUnit;
    }

    public void runForMatch(OfficeUnit unit, OfficeRuntime officeRuntime) {
        funcBase.runForMatch(unit, officeRuntime);
    }

    public TypeItem getType() {
        return TextRangeTypeItem.INSTANCE;
    }
}
